﻿// JScript File
var isFilterShow = false;
var path = document.location.search.substring(1).split('=')[1];
function checkDel(gv) {
    if (gv.GetSelectedRowCount() > 0) {
        if (confirm('Bạn có muốn xóa những record được chọn không? \n\nChú ý : Khi xóa record này, các thông tin liên quan tới đối tượng này cũng sẽ bị xóa.\n Nếu thông tin này liên quan đến những dữ liệu không thể xóa thì bạn phải xóa các dữ liệu liên quan trước, nếu không hành động xóa sẽ không có hiệu lực.'))
            gv.PerformCallback('delselect');
    } else
        alert('Bạn chưa chọn record nào để xóa !');
}
function checkDelTree(tree) {
    if (confirm('Bạn có muốn xóa record được chọn không?'))
        tree.PerformCallback('delselect');
}
function UpdateCustomizationWindowValue() {
    var element = document.getElementById("btnCustWindow");
    if (element == null) return;
    element.value = (grid.IsCustomizationWindowVisible() ? "Hide" : "Show") + " Customization Window";
}
function ShowHideCustomizationWindow() {
    if (grid.IsCustomizationWindowVisible())
        grid.HideCustomizationWindow();
    else grid.ShowCustomizationWindow();
    UpdateCustomizationWindowValue();
}

function HideCreatePopup() {
    for (var i = 0; i < window.parent.popupCreateNew.GetWindowCount(); i++)
        if (window.parent.popupCreateNew.IsWindowVisible(window.parent.popupCreateNew.GetWindow(i))) {
            window.parent.popupCreateNew.HideWindow(window.parent.popupCreateNew.GetWindow(i));
            break;
        }
}
function printPreviewDiv(elementId) {
    var printContent = document.getElementById(elementId);
    var windowUrl = 'about:blank';
    var uniqueName = new Date();
    var windowName = 'Print' + uniqueName.getTime();
    var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');
    var printPreviewObject = '<object id="printPreviewElement" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';

    printWindow.document.write(printContent.innerHTML);
    printWindow.document.write(printPreviewObject);
    printWindow.document.write('<script language=JavaScript>');
    printWindow.document.write('printPreviewElement.ExecWB(7, 2);');
    printWindow.document.write('printPreviewElement.outerHTML = "";');
    printWindow.document.write('</script>');
    printWindow.document.close();
    printWindow.focus();
    printWindow.close();
}

function reCalculator() {
    var soluong = parseInt(txtQty.GetText());
    var dongia = parseFloat(txtUnitPrice.GetText());
    var thanhtien = Math.round(soluong * dongia * 1000) / 1000;
    var giamgia = parseFloat(txtGiamgia.GetText());
    var thuesuat = parseFloat(txtThuesuat.GetText());
    var tongcong = Math.round((soluong * dongia - giamgia + thuesuat) * 1000) / 1000

    txtThanhtien.SetText(thanhtien);
    txtSauGiamgia.SetText(thanhtien - giamgia);
    txtTotal.SetText(tongcong);
}
function reCalculatorNXT() {
    var soluong = parseInt(txtQty.GetText());
    var dongia = parseFloat(txtUnitPrice.GetText());
    var thanhtien = Math.round(soluong * dongia * 1000) / 1000;
    txtThanhtien.SetText(thanhtien);
}
function setColumnVisible(grid) {
    var width = screen.width;


}

function OnUpdateClick(editor) {

    if (ASPxClientEdit.ValidateGroup("editForm")) {
        AspxGV1.UpdateEdit();
    }

}
function OnUpdateClick4(editor) {

    if (ASPxClientEdit.ValidateGroup("editForm")) {
        AspxGV2.UpdateEdit();
    }

}
function OnUpdate_NewClick() {

    if (ASPxClientEdit.ValidateGroup("editForm")) {
        AspxGV1.UpdateEdit();
        setTimeout("AspxGV1.AddNewRow()", 500);
    }

}
function OnUpdateClick2(editor, gv) {

    if (ASPxClientEdit.ValidateGroup("editForm2")) {
        gv.UpdateEdit();
    }

}
function OnUpdateClick3(gv) {

    if (ASPxClientEdit.ValidateGroup("editForm")) {
        gv.UpdateEdit();
    }

}
function OnUpdateClickByGvID(gv) {

    if (ASPxClientEdit.ValidateGroup("editForm")) {
        gv.UpdateEdit();
    }

}

function combineURLParams(url, param) {
    if (url.lastIndexOf('type=') > 0) {
        return url.substr(0, url.lastIndexOf('type=') - 1) + '?type=' + param;
    }
    else {
        return url + '?type=' + param;
    }
}

function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y);
        }
    }
}

function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}

function newWindow(URL) {

    myRef = window.open(URL, 'mywin', 'left=20,top=20,width=500,height=500,toolbar=0,resizable=0');
}
function openWindow(URL) {
    //    var dialogFeatures = 'center:yes; dialogWidth:1000px; location:no;dialogHeight:530px; edge:raised; help:no; resizable:yes; scroll:yes; status:no; statusbar:no; toolbar:no; menubar:no; addressbar:no; titlebar:no;';
    //    window.showModalDialog(URL, "", dialogFeatures);
    var h = 650, w = 1160;
    var left = (screen.width - w) / 2;
    var top = 10; // top = (screen.height - h) / 2 - 100;
    if (screen.width < 1160) {
        w = 1000;
        left = 0;
    }

    var dialogFeatures = 'left=' + left + ',top=' + top + ',width=' + w + ',height=' + h + ',toolbar=0,resizable=0, ';
    window.open(URL, "", dialogFeatures);

}
function openMiniWindow(URL, w, h) {
    var left = (screen.width / 2) - (w / 2);
    var top = (screen.height / 2) - (h / 2);
    //var dialogFeatures = 'center:yes; dialogWidth:' + w + 'px; location:no;dialogHeight:' + h + 'px; edge:raised; help:no; resizable:yes; scroll:yes; status:no; statusbar:no; toolbar:no; menubar:no; addressbar:no; titlebar:no;dialogLeft:' + left + 'px;dialogTop:' + top + 'px';
    var dialogFeatures = 'left=' + left + ',top=' + top + ',width=' + w + ',height=' + h + ',toolbar=0,resizable=0';
    window.showModalDialog(URL, "", dialogFeatures);

}
function openModalWindow(URL) {
    var h = 650, w = 1160;
    var left = (screen.width - w) / 2;
    var top = 10; // top = (screen.height - h) / 2 - 100;
    if (screen.width < 1160) {
        w = 1000;
        left = 0;
    }

    var dialogFeatures = 'left=' + left + ',top=' + top + ',width=' + w + ',height=' + h + ',toolbar=0,resizable=0, ';
    window.open(URL, "", dialogFeatures);

}
function reloadControl(id, gv) {
    gv.PerformCallback('focus' + id);
}


function OnDateEditGotFocus(s, e) {

    if (s.GetValue() == null) {
        var date = new Date();
        s.SetDate(date);
    }
}

function trim(str) {
    str = str.replace(/^\s+/, '');
    for (var i = str.length - 1; i >= 0; i--) {
        if (/\S/.test(str.charAt(i))) {
            str = str.substring(0, i + 1);
            break;
        }
    }
    return str;
}
